#ifndef H_SOUNDPLAYER
#define H_SOUNDPLAYER

#include <stdio.h>
#include <stdint.h>
#include "../include/format.h"
#include "../include/arg_parse.h"


#define VERSION "0.4"
#define BUF_SIZE 4096
#define stringfind(X, Y) nstringfind(X, Y, 0) //I demand stringfind
#define SET_OVERRIDE(X) env->overrides |= X
#define FLAGSET(X) env->overrides&(X)
#define FLAGUNSET(X) !(env->overrides&(X))

//gsoundplayer statuses
enum sp_status {
	SP_IDLE,
	SP_PLAY,
	SP_PAUSE,
	SP_STOP,
	SP_ERROR
};

enum sp_overrides {
	SP_OVERRIDE_FORMAT = 1,
	SP_OVERRIDE_CHANNEL,
	SP_OVERRIDE_HERTZ = 4,
	SP_OVERRIDE_FILTER = 8
};

typedef void (*progress_callback)(uint32_t bytes_elapsed, uint32_t bytes_total); //progress callback signature
typedef void* (*filter_callback)(char* buffer, uint32_t buffer_size); //signature for filter callback
typedef void (*message_callback)(const char* format, ...); //signature for message callback

struct _environment {
	void* pcm_handle;
	const char* filename;
	const char* audio_device;
	progress_callback progress; //get progress from decoder
	filter_callback filter; //apply a filter to a buffer before playing
	message_callback message; //display error messages and other useful information
	unsigned long size;
	int isfifo;
	int help;
	int audio_out; //device selection
	int format; //decode format selection
	int rate;
	int channels;
	int bit_depth;
	int bit_depth_alsa; //alsa uses an enum and its too much work too convert twice
	int buffer_size;
	int noid3;
	int retry_threshold;
	int status; //signal the running decoder function to stop
	char overrides;
};

typedef struct _environment* environment_t;

//declaration of functions
environment_t new_soundplayer_environment();
int nstringfind(char * string, char * pattern, long num);
char* concat(char* src1, char* src2); //string concatenator
int qualify_filename(char* filename);

//find "what" in the buffer "where" until "limit" bytes are reached
int grep(char *what, char *where, int limit);

//find the length of "string", "string" must be null terminated
int len(const char *string);

//compare two null terminated strings
int cmp (const char *what, const char *where);

//defaults declarations
void sp_progress_default(uint32_t bytes_elapsed, uint32_t bytes_total);
void* sp_filter_default(char* buffer, uint32_t buffer_size);
int sp_set_use_filter(int newval);

#endif

#ifndef H_SOUNDMODULE
#define H_SOUNDMODULE

//define functions used to output audio
#include "../include/soundmodules.h"

#endif
